$(function () {
    var ue = UE.getEditor('editor', {
        'serverUrl': '/ueditor/upload/'
    });

    $('#submit-btn').click(function (event) {
        event.preventDefault()
        var title_input = $("input[name='title']");
        var board_select = $("select[name='board_id']");
        var title = title_input.val();
        var board_id = board_select.val();
        var content = ue.getContent();
        zlajax.post({
            'url': '/add_post',
            'data': {
                'title': title,
                'content': content,
                'board_id': board_id
            },
            'success': function (data) {
                if (data['code'] == 200) {
                    zlalert.alertConfirm({
                        'msg': '帖子发布成功',
                        'confirmText': '再发一篇',
                        'cancelText': '回到首页',
                        'confirmCallback': function () {
                            title_input.val('');
                            ue.setContent('');

                        },
                        'cancelCallback': function () {
                            window.location = '/';
                        },
                    });
                } else {
                    zlalert.alertInfo(data['message']);
                }

            }
        });
    });
});
